package com.qf.service.impl;

import com.qf.bean.Permission;
import com.qf.bean.User;
import com.qf.mapper.PermissionMapper;
import com.qf.mapper.UserMapper;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * projectName: 2103--RBAC
 *
 * @author: MaTianWei
 * time: 2021/7/8 20:48
 * description:
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private PermissionMapper permissionMapper;


    @Override
    public Map login(User user) {

        //处理参数
        //调用数据库
        User userNew = userMapper.query(user);

        Map map = new HashMap();
        if (userNew == null) {
            map.put("code",0);
            return map;
        }
        List<Permission> permissions = permissionMapper.query(userNew.getuId());
        //处理返回值
        map.put("code",1);
        map.put("user",userNew);
        map.put("permission",permissions);
        return map;
    }
}
